// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Requests;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using Elastic.Transport;
using Elastic.Transport.Extensions;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.Security;

public sealed partial class HasPrivilegesUserProfileRequestParameters : RequestParameters
{
}

/// <summary>
/// <para>
/// Determines whether the users associated with the specified profile IDs have all the requested privileges.
/// </para>
/// </summary>
public sealed partial class HasPrivilegesUserProfileRequest : PlainRequest<HasPrivilegesUserProfileRequestParameters>
{
	internal override ApiUrls ApiUrls => ApiUrlLookup.SecurityHasPrivilegesUserProfile;

	protected override HttpMethod StaticHttpMethod => HttpMethod.POST;

	internal override bool SupportsBody => true;

	internal override string OperationName => "security.has_privileges_user_profile";

	[JsonInclude, JsonPropertyName("privileges")]
	public Elastic.Clients.Elasticsearch.Serverless.Security.PrivilegesCheck Privileges { get; set; }

	/// <summary>
	/// <para>
	/// A list of profile IDs. The privileges are checked for associated users of the profiles.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("uids")]
	public ICollection<string> Uids { get; set; }
}

/// <summary>
/// <para>
/// Determines whether the users associated with the specified profile IDs have all the requested privileges.
/// </para>
/// </summary>
public sealed partial class HasPrivilegesUserProfileRequestDescriptor : RequestDescriptor<HasPrivilegesUserProfileRequestDescriptor, HasPrivilegesUserProfileRequestParameters>
{
	internal HasPrivilegesUserProfileRequestDescriptor(Action<HasPrivilegesUserProfileRequestDescriptor> configure) => configure.Invoke(this);

	public HasPrivilegesUserProfileRequestDescriptor()
	{
	}

	internal override ApiUrls ApiUrls => ApiUrlLookup.SecurityHasPrivilegesUserProfile;

	protected override HttpMethod StaticHttpMethod => HttpMethod.POST;

	internal override bool SupportsBody => true;

	internal override string OperationName => "security.has_privileges_user_profile";

	private Elastic.Clients.Elasticsearch.Serverless.Security.PrivilegesCheck PrivilegesValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Security.PrivilegesCheckDescriptor PrivilegesDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Security.PrivilegesCheckDescriptor> PrivilegesDescriptorAction { get; set; }
	private ICollection<string> UidsValue { get; set; }

	public HasPrivilegesUserProfileRequestDescriptor Privileges(Elastic.Clients.Elasticsearch.Serverless.Security.PrivilegesCheck privileges)
	{
		PrivilegesDescriptor = null;
		PrivilegesDescriptorAction = null;
		PrivilegesValue = privileges;
		return Self;
	}

	public HasPrivilegesUserProfileRequestDescriptor Privileges(Elastic.Clients.Elasticsearch.Serverless.Security.PrivilegesCheckDescriptor descriptor)
	{
		PrivilegesValue = null;
		PrivilegesDescriptorAction = null;
		PrivilegesDescriptor = descriptor;
		return Self;
	}

	public HasPrivilegesUserProfileRequestDescriptor Privileges(Action<Elastic.Clients.Elasticsearch.Serverless.Security.PrivilegesCheckDescriptor> configure)
	{
		PrivilegesValue = null;
		PrivilegesDescriptor = null;
		PrivilegesDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// A list of profile IDs. The privileges are checked for associated users of the profiles.
	/// </para>
	/// </summary>
	public HasPrivilegesUserProfileRequestDescriptor Uids(ICollection<string> uids)
	{
		UidsValue = uids;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (PrivilegesDescriptor is not null)
		{
			writer.WritePropertyName("privileges");
			JsonSerializer.Serialize(writer, PrivilegesDescriptor, options);
		}
		else if (PrivilegesDescriptorAction is not null)
		{
			writer.WritePropertyName("privileges");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Security.PrivilegesCheckDescriptor(PrivilegesDescriptorAction), options);
		}
		else
		{
			writer.WritePropertyName("privileges");
			JsonSerializer.Serialize(writer, PrivilegesValue, options);
		}

		writer.WritePropertyName("uids");
		JsonSerializer.Serialize(writer, UidsValue, options);
		writer.WriteEndObject();
	}
}